// Problem: 
// Contest: 
// URL: 
// Memory Limit: 
// Time Limit: 
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,a,n) for(int (i)=(a);(i)<=(n);(i)++)
#define pre(i,a,n) for(int (i)=(a);(i)>=(n);(i)--)
//const int N,mod;
inline int read(){
	int s=0,w=1;
	char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
	while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
	return s*w;
}
void solve()
{
	int n,m;
	cin>>n>>m;
	vector<int> v(n+1),w(m+1);
	rep(i,1,n)cin>>v[i];
	rep(i,1,m)cin>>w[i];
	int i=1,j=1;
	int ans=0;
	while(i!=n&&j!=m)
	{
		if(v[i]==w[j]){i++,j++;}
		else if(v[i]<w[j])
		{
			w[j]-=v[i];
			i++;
			ans++;
		}
		else
		{
			v[i]-=w[j];
			j++;
			ans++;
		}
	}
	cout<<ans<<endl;
}
signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	int T=1;
//	cin>>T;
	while(T--)
	{
		solve();
	}
	return 0;
}
